/**
 * 
 */
package study.lgf.action.form;

import com.opensymphony.xwork2.ActionSupport;

import study.lgf.model.People;

/**
 * @author rj
 *
 */
public class VaildateFormAction extends ActionSupport{
	private static final long serialVersionUID = 1L;
	private People personBean;
	
	@Override
	public String execute() throws Exception {
		return SUCCESS;
	}
	
	@Override
	public String input(){
		return INPUT;
	}
	/**
	 * Struct2自帶校驗
	 */
	@Override
	public void validate() {
		if(personBean != null){
			if (personBean.getFirstName().length() == 0) {
				addFieldError("personBean.firstName", "名字  不能为空.");
			}
			if(personBean.getLastName().length() == 0){
				addFieldError("personBean.lastName", "姓  不能为空..");
			}
			if (personBean.getEmail().length() == 0) {
				addFieldError("personBean.email", "Email  不能为空.");
			}
			if (personBean.getAge() == null ) {
				addFieldError("personBean.age","请填写年龄信息");
			}else if (personBean.getAge().intValue() < 18) {
				addFieldError("personBean.age","年龄至少18");
			}
		}
	}

	public People getPersonBean() {
		return personBean;
	}
	public void setPersonBean(People personBean) {
		this.personBean = personBean;
	}
}
